package com.luoqiz.demo.udpDemo;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;

public class Sender {

	public static void main(String[] args) {
		try {
			DatagramSocket sender=new DatagramSocket(11000);
			byte[] buf=new byte[1024];
			DatagramPacket p=new DatagramPacket(buf, buf.length);
			SocketAddress address=new InetSocketAddress("127.0.0.1", 9999);
			p.setSocketAddress(address);
			for(int i=0;i<10;i++) {
				p.setData(("hello word"+i).getBytes());
				sender.send(p);
			}
			
			sender.close();
			System.out.println("发送完成");
		} catch (SocketException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
